package com.zcyh.exam.service;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zcyh.exam.config.LoginContext;
import com.zcyh.exam.config.LoginInfo;
import com.zcyh.exam.config.exception.BusinessException;
import com.zcyh.exam.model.common.ResultCode;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;


/**
 * service 基类
 * @author zengjintao
 * @version 1.0
 * @create_at 2020/3/8 10:40
 */
public abstract class BaseService<M extends BaseMapper<T>, T> extends CrudService<M, T> {
    @Autowired
    protected HttpServletRequest request;
    @Autowired
    private LoginContext loginContext;
    public LoginInfo getUserInfo() {
        return loginContext.getLoginInfo();
    }

    /*当前使用人id*/
    public String getUserId() {
        String userId = loginContext.getLoginInfo().getUserId();
        if(StringUtils.isBlank(userId)){
            throw new BusinessException(new ResultCode(ResultCode.FAIL, "用户未登陆"));
        }
        return userId;
    }
}
